import Scanner from './Scanner'
import nestTokens from './nestTokens';

// 将模板字符串变为tokens数组
export default function Totokens(tempStr) {
    var tokens = [];
    var words;
    // 创建扫描器：
    var scanner = new Scanner(tempStr)
    while (!scanner.eos()) {
        words = scanner.scanUntil('{{');
        if (words != '') {
            // 
            tokens.push(['text', words])
        }
        scanner.scan('{{');
        words = scanner.scanUntil('}}');
        if (words != '') {
            // 判断首字符是否围殴#或者/
            if (words[0] == "#") {
                // 将words下标为1的开始存,
                tokens.push(['#', words.substring(1)])
            } else if (words[0] == "/") {
                // 将words下标为1的开始存
                tokens.push(['/', words.substring(1)])
            } else {
                tokens.push(['name', words])
            }
        }
        scanner.scan('}}');
    }
    return nestTokens(tokens);
}